/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:54 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class NhomnguoidungDAL : SqlProvider<NhomnguoidungEntity>
    {
        static NhomnguoidungDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                NhomnguoidungEntity entity = new NhomnguoidungEntity();
				entity.PK_iNhomnguoidungID = Int16.Parse("0"+dr["PK_iNhomnguoidungID"].ToString());
				entity.sTennhom = dr["sTennhom"].ToString();
                entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static NhomnguoidungEntity GetOne(Int16 PK_iNhomnguoidungID)
        {
            string cmdName = "spNhomnguoidung_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iNhomnguoidungID", PK_iNhomnguoidungID);
            NhomnguoidungEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static NhomnguoidungEntity GetBysKyhieu(String sKyhieu)
        {
            string cmdName = "spNhomnguoidung_GetBysKyhieu";
            SqlParameter p = new SqlParameter("@sKyhieu", sKyhieu);
            NhomnguoidungEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<NhomnguoidungEntity> GetAll()
        {
            string cmdName = "spNhomnguoidung_Get";
            return GetList(cmdName);
        }
        
        public static int Add(NhomnguoidungEntity entity)
        {
            string cmdName = "spNhomnguoidung_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(NhomnguoidungEntity entity)
        {
            string cmdName = "spNhomnguoidung_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iNhomnguoidungID)
        {
            string cmdName = "spNhomnguoidung_Delete";
            SqlParameter p = new SqlParameter("@PK_iNhomnguoidungID", PK_iNhomnguoidungID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(NhomnguoidungEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iNhomnguoidungID", entity.PK_iNhomnguoidungID);
			p[1] = new SqlParameter("@sTennhom", entity.sTennhom);
			p[2] = new SqlParameter("@sGhichu", entity.sGhichu);
            p[3] = new SqlParameter("@sKyhieu", entity.sKyhieu);
            return p;
        }
        #endregion
       
    }
}